<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var arr1 = [1, 2, 3, 4];
        var arr2 = [3, 4, 5, 6];
        //求交集
        function intersection(...arg) {
            var arr = arg[0].filter((item) => arg[1].includes(item));
            return arr;
        }
        //求差集
        function difference(...arg) {
            var arr = union(...arg).filter((item) => !intersection(...arg).includes(item));
            return arr;
        }
        console.log(intersection(arr1, arr2));//[3,4]
        console.log(difference(arr1, arr2));//[1,2,5,6]

    </script>
</body>

</html>